/*
 * BankCardModel.java
 * business
 *
 * Created by SunDing on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.data.model;

import com.yidiandao.business.constant.Urls;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.data.net.BaseRequest;
import com.yidiandao.business.data.net.BaseResponse;
import com.yidiandao.business.data.net.NetBiz;
import com.yidiandao.business.data.net.NetListener;
import com.yidiandao.business.data.net.exception.BizErrorInfo;
import com.yidiandao.business.data.net.exception.NetErrorInfo;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.displaylistitem.BankCardListItem;
import com.yidiandao.business.utils.PreferenceUtils;
import com.yidiandao.business.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 银行卡相关
 * <p>
 * Created by SunDing(dindding@163.com) on 2017/2/21 9:44
 */
public class BankCardModel implements IBankCardModel {

    NetBiz mNetBiz = new NetBiz();

    @Override
    public void getBankCardInfo(String tag, final OnLoadListener<List<DisplayListItem>> listener) {
        BaseRequest request = new BaseRequest();
        request.setTag(tag);
        request.setToken(PreferenceUtils.getToken(UIUtils.getContext()));
        request.setUrl(Urls.LOCATION_DOMAIN);
        mNetBiz.sendGetRequest(request, BaseResponse.class, new NetListener<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {

                List<DisplayListItem> list = new ArrayList<>();
                for (int i = 0; i < 10; i++) {
                    list.add(new BankCardListItem(new Goods()));
                }
                if (null != listener) {
                    listener.onSuccess(list);
                }
            }

            @Override
            public boolean onError(NetErrorInfo netErrorInfo) {
                if (null != listener) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public boolean onFailed(BizErrorInfo bizErrorInfo) {
                if (null != listener) {
                    listener.onFailed();
                }
                return true;
            }

            @Override
            public void onFinal() {
                if (null != listener) {
                    listener.onFinal();
                }
            }
        });
    }
}
